{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "悟空的初始血量是1000\n",
      "悟空的兵器是“金箍棒”，可以造成150点伤害\n",
      "悟空的防御每次减少 20 %伤害\n",
      "悟空的大招可以造成每个妖怪150点伤害\n",
      "八戒的初始血量是700\n",
      "八戒的兵器是“九齿钉耙”，可以造成100点伤害\n",
      "八戒的防御每次减少 10 %伤害\n",
      "八戒的大招可以造成每个妖怪100点伤害\n",
      "悟净的初始血量是700\n",
      "悟净的兵器是“降妖宝杖”，可以造成100点伤害\n",
      "悟净的防御每次减少 10 %伤害\n",
      "悟净的大招可以造成每个妖怪100点伤害\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(100, 0.1, 100)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class WestTeam(object): \n",
    "    \n",
    "    def __init__(self,name,blood):\n",
    "        self.name = name\n",
    "        self.blood = blood\n",
    "        print(f'{self.name}的初始血量是{self.blood}')\n",
    "        \n",
    "    def Weapon(self,Weapon_name,num_1):\n",
    "        print(f'{self.name}的兵器是“{Weapon_name}”，可以造成{num_1}点伤害')\n",
    "        return num_1\n",
    "        \n",
    "    def defense(self,num_2):\n",
    "        print(f'{self.name}的防御每次减少 {num_2} %伤害')\n",
    "        return num_2 * 0.01\n",
    "        \n",
    "    def skill(self,num_3):\n",
    "        print(f'{self.name}的大招可以造成每个妖怪{num_3}点伤害')\n",
    "        return num_3\n",
    "        \n",
    "wukong = WestTeam('悟空',1000)\n",
    "wukong.Weapon('金箍棒',150),wukong.defense(20),wukong.skill(150)\n",
    "\n",
    "bajie = WestTeam('八戒',700)\n",
    "bajie.Weapon('九齿钉耙',100),bajie.defense(10),bajie.skill(100)\n",
    "\n",
    "wujing = WestTeam('悟净',700)\n",
    "wujing.Weapon('降妖宝杖',100),wujing.defense(10),wujing.skill(100)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "狮子精的初始血量是750\n",
      "狮子精的兵器是“大金刀”，可以造成100点伤害\n",
      "狮子精的防御每次减少 15 %伤害\n",
      "狮子精的大招可以造成每个神仙100点伤害\n",
      "大象精的初始血量是750\n",
      "大象精的兵器是“大铁杵”，可以造成100点伤害\n",
      "大象精的防御每次减少 15 %伤害\n",
      "大象精的大招可以造成每个神仙100点伤害\n",
      "大鹏精的初始血量是750\n",
      "大鹏精的兵器是“大长枪”，可以造成100点伤害\n",
      "大鹏精的防御每次减少 15 %伤害\n",
      "大鹏精的大招可以造成每个神仙100点伤害\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(100, 0.15, 100)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class MonsterTeam(object): \n",
    "    \n",
    "    def __init__(self,name,blood):\n",
    "        self.name = name\n",
    "        self.blood = blood\n",
    "        print(f'{self.name}的初始血量是{self.blood}')\n",
    "        \n",
    "    def Weapon(self,Weapon_name,num_1):\n",
    "        print(f'{self.name}的兵器是“{Weapon_name}”，可以造成{num_1}点伤害')\n",
    "        return num_1\n",
    "        \n",
    "    def defense(self,num_2):\n",
    "        print(f'{self.name}的防御每次减少 {num_2} %伤害')\n",
    "        return num_2 * 0.01\n",
    "        \n",
    "    def skill(self,num_3):\n",
    "        print(f'{self.name}的大招可以造成每个神仙{num_3}点伤害')\n",
    "        return num_3\n",
    "        \n",
    "f_wang = MonsterTeam('狮子精',750)\n",
    "f_wang.Weapon('大金刀',100),f_wang.defense(15),f_wang.skill(100)\n",
    "\n",
    "s_wang = MonsterTeam('大象精',750)\n",
    "s_wang.Weapon('大铁杵',100),s_wang.defense(15),s_wang.skill(100)\n",
    "\n",
    "t_wang = MonsterTeam('大鹏精',750)\n",
    "t_wang.Weapon('大长枪',100),t_wang.defense(15),t_wang.skill(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wukong的初始血量是1000\n",
      "bajie的初始血量是700\n",
      "wujing的初始血量是700\n",
      "lion的初始血量是750\n",
      "elephant的初始血量是750\n",
      "bird的初始血量是750\n"
     ]
    }
   ],
   "source": [
    "wukong = WestTeam('wukong',1000)\n",
    "bajie = WestTeam('bajie',700)\n",
    "wujing = WestTeam('wujing',700)\n",
    "\n",
    "def who_fight(name):\n",
    "    if name == 'wukong':            \n",
    "        hit,defense,hit_all = wukong.Weapon('金箍棒',150),wukong.defense(20),wukong.skill(150)\n",
    "    elif name == 'bajie':    \n",
    "        hit,defense,hit_all = bajie.Weapon('九齿钉耙',100),bajie.defense(10),bajie.skill(100)\n",
    "    elif name == 'wujing':      \n",
    "        hit,defense,hit_all = wujing.Weapon('降妖宝杖',100),wujing.defense(10),wujing.skill(100)  \n",
    "    return hit,defense,hit_all\n",
    "\n",
    "lion = MonsterTeam('lion',750)\n",
    "elephant = MonsterTeam('elephant',750)\n",
    "bird = MonsterTeam('bird',750)\n",
    "\n",
    "def who_fight2(name):\n",
    "    if name == 'lion':\n",
    "        hit,defense,hit_all = lion.Weapon('大金刀',100),lion.defense(15),lion.skill(100)\n",
    "    elif name == 'elephant':\n",
    "        hit,defense,hit_all = elephant.Weapon('大铁杵',100),elephant.defense(15),elephant.skill(100)\n",
    "    elif name == 'bird':\n",
    "        hit,defense,hit_all = bird.Weapon('大长枪',100),bird.defense(15),bird.skill(100) \n",
    "    return hit,defense,hit_all\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入攻击者和攻击对象，“,”隔开:wukong,lion\n",
      "wukong的兵器是“金箍棒”，可以造成150点伤害\n",
      "wukong的防御每次减少 20 %伤害\n",
      "wukong的大招可以造成每个妖怪150点伤害\n",
      "lion的兵器是“大金刀”，可以造成100点伤害\n",
      "lion的防御每次减少 15 %伤害\n",
      "lion的大招可以造成每个神仙100点伤害\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "'str' object has no attribute 'blood'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-29-261b8c183399>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      5\u001b[0m         \u001b[0mhit\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0md\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mhit_all\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mwho_fight\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfight_name\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m         \u001b[0mdefense\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mwho_fight2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfight_name\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m         \u001b[0mfight_name\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mblood\u001b[0m \u001b[1;33m-=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0mdefense\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mhit\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'blood'"
     ]
    }
   ],
   "source": [
    "if __name__ == '__main__':\n",
    "    while True:\n",
    "        \n",
    "        fight_name = input('请输入攻击者和攻击对象，“,”隔开:').split(',')\n",
    "        hit,*d,hit_all = who_fight(fight_name[0])\n",
    "        defense = who_fight2(fight_name[1])[1]\n",
    "        fight_name[1].blood -= (1 - defense) * hit\n",
    "        \n",
    "        \n",
    "        \n",
    "        \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
